package com.itheima;

import java.util.*;

/**
 * @ProjectName: ybxy6
 * @Titile: CollectionsDemo
 * @Author: 鲁伍加
 * @Description: TODO
 * 演示collections工具类的使用
 */
public class CollectionsDemo {
    //抽取下面代码为test0（）
    public static void main(String[] args){
        extracted();
    }

    private static void extracted() {
        List<String> list = new LinkedList<>();//多态带来的好处
        Collections.addAll(list,"张三","李四","王五","赵六");
        list.forEach(System.out::println);
        System.out.println("---------------");
        //打乱集合顺序
        Collections.shuffle(list);
        list.forEach(System.out::println);
    }

    public static void test1(){
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,5,6,7,8,9,10);
        //按照倒序给集合排序
        Collections.sort(list);
        list.forEach(System.out::println);
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                //按照倒序给集合排序
                return o2 - o1;
            }
        });
        System.out.println("---------------------");
        list.forEach(System.out::println);

        //让学生Student类实现Comparable接口
        List<Student> list1 = new ArrayList<>();
        list1.add(new Student("张三",18));
        list1.add(new Student("李四",19));
        list1.add(new Student("王五",20));
        Collections.sort(list1);
        list1.forEach(System.out::println);
//        List<Integer> synchroizedList = Collections.synchronizedList(list);
    }

}
